package com.me;

import com.me.test.util.S3ToolUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
@Slf4j
public class DemoApplication {

    public static void main(String[] args) {
        //版本1
        //版本3
        SpringApplication.run(DemoApplication.class, args);
        /*try {
            test();
        }catch (Exception ex){
            ex.printStackTrace();
        }*/
    }

    public static void test() throws IOException {
        //免费测试网速 https://www.browserscan.net/zh/speed-test
        String accessKeyId="401b561e0cb8cf415a925d71d4f5ee38";
        //S3加密访问密钥
        String secretAccessKey="3fc62eb056624c299ebb8672bfc926166e2e8d047a14d4280b39839a72ca862a";
        //服务端点
        String endPoint="https://3e279757b33d806150f6653ebf4fbe9a.r2.cloudflarestorage.com";
        //桶名
        String bucketName="test";
        S3ToolUtils s3ToolUtils = new S3ToolUtils(accessKeyId,secretAccessKey,endPoint,bucketName);
        /*InputStream ins = s3ToolUtils.downloadFile("20140611165023_eBALy.jpeg");

        OutputStream os = new FileOutputStream(new File("E:\\haishen\\jingcw.jpeg"));
        int bytesRead = 0;
        byte[] buffer = new byte[8192];
        while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        os.close();
        ins.close();*/
        long start = System.currentTimeMillis();
        //for (int i=10;i<18;i++){
        String fileurl = "https://haishen-test.oss-cn-beijing.aliyuncs.com/admin/2024/4/msdia80.dll";
        //File file = FileUtil.urlToFile("https://haishen-test.oss-cn-beijing.aliyuncs.com/admin/2024/4/msdia80.dll");
        //s3ToolUtils.uploadFile(file,"abcd/haishen/"+1+"msdia80.dll");
        URL url1 = new URL(fileurl);
        s3ToolUtils.uploadFileByStream(url1.openStream(),"n2n/msdia80.dll");
        //}


        /*String fileurl = "https://haishen-test.oss-cn-beijing.aliyuncs.com/admin/2024/4/20241017133314_679919.png";
        URL url1 = new URL(fileurl);
        //File file = new File("E:\\haishen\\msdia80.dll");
        InputStream inputStream = url1.openStream();
        System.out.println("inputstream:"+(System.currentTimeMillis()-millis));
        s3ToolUtils.uploadFileByStream(inputStream,"abcd/haishen/20241017133314_679919.png");*/
        long hs = System.currentTimeMillis()- start;
        log.info("upload: {}",hs);
    }

}
